﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;

namespace MqttServerTest.Model
{
    public class Status
    {
        static long _id = 1;
        [JsonProperty(Order = -999, PropertyName = "messageId")]
        //[JsonPropertyName("messageId")]
        public long MessageId { get; set; } = _id == long.MaxValue ? _id = 1 : _id++;
        [JsonProperty(Order = -999, PropertyName = "timestamp")]
        //[JsonPropertyName("timestamp")]
        public long Timestamp { get; set; } = Helper.GetTimeStamp();

    }

    public class Hwinfo : Status
    {
        public string Type { get; set; } = "v1";
    }

    /// <summary>
    /// 配置串口
    /// </summary>
    public class PeiRS : Status
    {
        /// <summary>
        /// 串口号
        /// </summary>
        public string Port { get; set; } = "com1";
        /// <summary>
        /// 是否启用
        /// </summary>
        public string Enabled { get; set; } = "true";
        /// <summary>
        /// 串口工作模式：tcp/udp/modbus，modbus模式为RS485接口独有
        /// </summary>
        public string Mode { get; set; } = "tcp_client";
        /// <summary>
        /// 透传模式下串口重连时间周期，默认值300。单位：秒
        /// </summary>
        public int Interval { get; set; } = 600;
        /// <summary>
        /// 透传模式下读时延，默认值1000。单位：毫秒
        /// </summary>
        public int Delay { get; set; } = 500;
        /// <summary>
        /// 波特率
        /// </summary>
        public int Baudrate { get; set; } = 19200;
        /// <summary>
        /// 数据位
        /// </summary>
        public int Databit { get; set; } = 8;
        /// <summary>
        /// 停止位
        /// </summary>
        public int Stopbit { get; set; } = 1;
        /// <summary>
        /// 校验位
        /// </summary>
        public string Checkdigit { get; set; } = "none";

    }

    /// <summary>
    /// 配置透传
    /// </summary>
    public class DtuSet : Status
    {
        /// <summary>
        /// 主服务器地址（支持域名）
        /// </summary>
        public string Server_0 { get; set; } = "192.168.10.55";
        /// <summary>
        /// 主服务器端口号
        /// </summary>
        public int Server_port0 { get; set; } = 55000;
        /// <summary>
        /// 子服务器1地址（支持域名）
        /// </summary>
        public string Server_1 { get; set; } = "192.168.10.155";
        /// <summary>
        /// 子服务器1端口号
        /// </summary>
        public int Server_port1 { get; set; } = 55000;
        /// <summary>
        /// 子服务器2地址（支持域名）
        /// </summary>
        public string Server_2 { get; set; } = "192.168.10.10";
        /// <summary>
        /// 子服务器2端口号
        /// </summary>
        public int Server_port2 { get; set; } = 5555;
        /// <summary>
        /// 子服务器3地址（支持域名）
        /// </summary>
        public string Server_3 { get; set; } = "192.168.10.110";
        /// <summary>
        /// 子服务器3端口号
        /// </summary>
        public int Server_port3 { get; set; } = 5555;
        /// <summary>
        /// 子服务器4地址（支持域名）
        /// </summary>
        public string Server_4 { get; set; } = "192.168.10.120";
        /// <summary>
        /// 子服务器4端口号
        /// </summary>
        public int Server_port4 { get; set; } = 5555;

        /// <summary>
        /// 子服务器5地址（支持域名）
        /// </summary>
        public string Server_5 { get; set; } = "192.168.10.103";
        /// <summary>
        /// 子服务器5端口号
        /// </summary>
        public int Server_port5 { get; set; } = 5555;
        /// <summary>
        /// 是否启用心跳
        /// </summary>
        public string Heart_enabled { get; set; } = "false";
        /// <summary>
        /// 心跳间隔时间,范围（30 - 3600）单位：秒
        /// </summary>
        public int Heart_interval { get; set; } = 60;
        /// <summary>
        /// 是否启用十六进制的心跳包
        /// </summary>
        public string Heart_hex { get; set; } = "false";
        /// <summary>
        /// 心跳报内容
        /// </summary>
        public string Heart { get; set; } = "string.Empty";
        /// <summary>
        /// 注册包模式：id/ccid/custom
        /// </summary>
        public string Register_mode { get; set; } = "ccid";
        /// <summary>
        /// 是否启用十六进制的注册包
        /// </summary>
        public string Register_hex { get; set; } = "false";
        /// <summary>
        /// 自定义注册包格式
        /// </summary>
        public string Register_custom { get; set; } = string.Empty;
    }

    /// <summary>
    /// 服务参数
    /// </summary>
    public class Sensor : Status
    {
        public string Enabled { get; set; } = "true";
        public string Port { get; set; } = "com1";
        public int Interval { get; set; } = 240;
        public int Delay { get; set; } = 1;

    }
    /// <summary>
    /// 寄存器
    /// </summary>
    public class Register
    {
        public string Name { get; set; } = "temp";
        public int Code { get; set; } = 3;
        public int Addr { get; set; } = 1;
        public string Type { get; set; } = "16ab";
        public string CollectionFormula { get; set; } = "";
    }
    /// <summary>
    /// 注册
    /// </summary>
    public class Registers : Status
    {
        public string Port { get; set; } = "com1";
        public string SensorTheme { get; set; } = "temper1";
        public int SensorAddr { get; set; } = 1;
        public Register[] RegisterList { get; set; } = new Register[] { new Register()
            //,new Register() { Name = "humidity", Code = 3, Addr = 2, Length = 2, CollectionFormula = "x/10" }
            };

    }
    /// <summary>
    /// 注销
    /// </summary>
    public class Unregister : Status
    {
        public string Port { get; set; } = "com1";
        public string SensorTheme { get; set; } = "temper1";

    }

    /// <summary>
    /// 写入参数
    /// </summary>
    public class RegisterR
    {
        public int Code { get; set; } = 6;
        public int Addr { get; set; } = 16;
        public int Length { get; set; } = 0;
        public int Value { get; set; } = 2;
        //public string[] Val { get; set; }
    }
    /// <summary>
    /// 写入传感器
    /// </summary>
    public class RegistersR : Status
    {
        public string Port { get; set; } = "com1";
        public int SensorAddr { get; set; } = 1;
        public RegisterR[] RegisterList { get; set; } = { new RegisterR() };

    }

    /// <summary>
    /// 控制设备
    /// </summary>
    public class Action : Status
    {
        public string Reboot { get; set; } = "false";

        public string Save { get; set; } = "false";
        public string Reset_App { get; set; } = "false";
    }

    /// <summary>
    /// 注册包
    /// </summary>
    public class Device : Status
    {
        public string device { get; set; }
        public string UUID { get; set; }
        public string DeviceModel { get; set; }
        public string SoftwareVersion { get; set; }
        public string IMSI { get; set; }
        public string Longitude { get; set; }
        public string Latitude { get; set; }

    }

    /// <summary>
    /// 固件升级
    /// </summary>
    public class FTPUp : Status
    {
        //public string Url = "ftp://192.168.4.200/hw1570l-a.bin";
        public string Url = "http://192.168.5.200:280/hw1570g-a_6.2.3.bin";
        public string Username = "test";
        public string Password = "1234";
        public int Tries = 5;
        public string Sha256sum = "";
        public string IsSave = "true";
    }

    public class Sms : Status
    {
        /// <summary>
        /// 电话号码。
        /// 按照标准格式书写，电话号码前需加上国家或地区代码
        /// 如：国内大陆地区的电话号码前须加上+86
        /// </summary>
        public string Phone { get; set; } = "+8617778221201";
        /// <summary>
        /// 短信内容
        /// </summary>
        public string Content { get; set; } = "报警记录有通知：2022年7月13日09-18-48系统产生报警记录，" +
            "请及时关注设备状态，确保系统运行安全。谢谢";
    }

    public class SensorData : Status
    {
        /// <summary>
        /// 串口号
        /// </summary>
        public string Port { get; set; }
        /// <summary>
        /// 传感器名称
        /// </summary>
        public string SensorTheme { get; set; }
        /// <summary>
        /// 传感器地址
        /// </summary>
        public int SensorAddr { get; set; }
        /// <summary>
        /// 寄存器名称
        /// </summary>
        public string RegisterName { get; set; } = "";
        /// <summary>
        /// 寄存器地址
        /// </summary>
        public int RegisterAddr { get; set; }
        /// <summary>
        /// 可读数据，配置公式后返回
        /// </summary>
        public decimal Data { get; set; }
    }

    public class TImeTEst
    {
        public long sendTime { get; set; }
        public string functionCode { get; set; }
        public string clientId { get; set; }
        public string code { get; set; }
        public double wendu { get; set; }
    }

    /// <summary>
    /// 设备AP
    /// </summary>
    public class SetAP : Status
    {
        public string Enabled { get; set; } = "true";
        public string Band { get; set; } = "2.4";
        public string SSID { get; set; } = "Huawow5G";
        public string VerificationMethod { get; set; } = "psk2";
        public string PassWord { get; set; } = "12345678";
        public string FastRoaming { get; set; } = "false";
        public string MobilityDomain { get; set; } = "ffff";
        public int Reassocication_Deadline { get; set; } = 20000;
        public string MACFilter { get; set; } = "deny";
        public string[] MACList { get; set; } = new string[]
        {
            "00:A1:1A:D3:46:71","0A:CF:4E:60:09:62","7D:FA:F3:5F:B6:81","AF:09:8A:C6:71:01",
            "0F:A4:1A:D3:46:72","0A:C3:4A:60:09:63","3A:FA:F3:5A:B6:80","F1:09:8A:C6:70:42",
            "0F:A4:1A:D3:46:73","0A:C3:4A:60:09:64","3A:FA:F3:5A:B6:82","F1:09:8A:C6:70:43",
            "0F:A4:1A:D3:46:74","0A:C3:4A:60:09:65","3A:FA:F3:5A:B6:83","F1:09:8A:C6:70:44",
            "0F:A4:1A:D3:46:75","0A:C3:4A:60:09:66","3A:FA:F3:5A:B6:84","F1:09:8A:C6:70:45",
            "0F:A4:1A:D3:46:76","0A:C3:4A:60:09:67","3A:FA:F3:5A:B6:85","F1:09:8A:C6:70:46",
            "0F:A4:1A:D3:46:77","0A:C3:4A:60:09:68","3A:FA:F3:5A:B6:86","F1:09:8A:C6:70:47",
            "0F:A4:1A:D3:46:78","0A:C3:4A:60:09:69","3A:FA:F3:5A:B6:87","F1:09:8A:C6:70:48",
            "0F:A4:1A:D3:46:79","0A:C3:4A:60:09:60","3A:FA:F3:5A:B6:88","F1:09:8A:C6:70:49",
            "0F:A4:1A:D3:46:70","0A:C3:4A:60:09:6E","3A:FA:F3:5A:B6:89","F1:09:8A:C6:70:40",
            "0F:A4:1A:D3:46:7A","0A:C3:4A:60:09:6D","3A:FA:F3:5A:B6:8A","F1:09:8A:C6:70:4A",
            "0F:A4:1A:D3:46:7B","0A:C3:4A:60:09:6C","3A:FA:F3:5A:B6:8C","F1:09:8A:C6:70:4B",
            "10:AB:1A:D1:46:7D","0A:C3:4E:65:09:6F","3D:FA:F3:6A:B6:8B","FF:09:8A:86:71:4C"
        };
    }

    /// <summary>
    /// 配置MESH
    /// </summary>
    public class SetMESH : Status
    {
        public string Enabled { get; set; } = "true";
        public string Bridge { get; set; } = "";
        public string SSID { get; set; } = "huawow";
        public string PassWord { get; set; } = "12345678";
        public int Frequency { get; set; } = 5745;
        public string Proto { get; set; } = "static";
        public string IPAddr { get; set; } = "192.168.200.5/24";
    }

    /// <summary>
    /// 配置DHCP
    /// </summary>
    public class SetDHCP : Status
    {
        public string Enabled { get; set; } = "true";
        public string Sequential_IP { get; set; } = "false";
        public int Leasemax { get; set; } = 1000;
        public string DNS1 { get; set; } = "";
        public string DNS2 { get; set; } = "";
        public DHCPServer[] ServerList { get; set; } = new DHCPServer[]
        {
            new DHCPServer()
        };

        public class DHCPServer
        {
            public string Name { get; set; } = "test";
            public string Interface { get; set; } = "vlan1";
            public string Start { get; set; } = "192.168.4.20";
            public string End { get; set; } = "192.168.4.50";
            public string Netmask { get; set; } = "255.255.255.0";
            public string GateWay { get; set; } = "192.168.4.1";
            public int Leasetime { get; set; } = 1;

        }

    }

    /// <summary>
    /// 配置RIP
    /// </summary>
    public class SetRIP : Status
    {
        public string Enabled { get; set; } = "true";
        public string Version { get; set; } = "2";
        public string Passive_Interface { get; set; } = "";
        public string Authentication { get; set; } = "none";
        public string PassWord { get; set; } = "";
        public string Interface { get; set; } = "";
        public int Update { get; set; } = 80;
        public int Timeout { get; set; } = 60;
        public int Garbage { get; set; } = 240;
        public string[] NetWork { get; set; } = new string[] { "192.168.40.0/24", "192.168.2550.0/24" };
        public string[] Neighbor { get; set; } = new string[] { };

    }

    /// <summary>
    /// 配置VLAN
    /// </summary>
    public class SetVlan : Status
    {
        public Vlan[] VlanList { get; set; } = new Vlan[] { new Vlan() };
        public class Vlan
        {
            public int ID { get; set; } = 1;
            public string LAN1 { get; set; } = "u";
            public string LAN2 { get; set; } = "u";
            public string LAN3 { get; set; } = "u";
            public string LAN4 { get; set; } = "u";
            public string IPaddr { get; set; } = "192.168.4.1/24";
            public int MTU { get; set; } = 1500;
        }
    }

    /// <summary>
    /// 配置地址转换
    /// </summary>
    public class SetSnat : Status
    {
        public Snat[] SNatRule { get; set; } = new Snat[] { new Snat() };

        public class Snat
        {
            public string Name { get; set; } = "WWW1";
            public string Interface { get; set; } = "wwan0";
            public string Proto { get; set; } = "ip";
            public string Type { get; set; } = "nat4";
            public string Source_IP { get; set; } = "192.168.5.0/24";
            public string Source_Port { get; set; } = "";
            public string Dest_IP { get; set; } = "";
            public string Start { get; set; } = "";
            public string Ends { get; set; } = "";
        }

    }

    /// <summary>
    /// 配置虚拟服务器
    /// </summary>
    public class SetDNat : Status
    {
        public Dnat[] DNatRule { get; set; } = new Dnat[] { new Dnat(),
            new Dnat()
            {
                Name="ttt",
                Proto="tcp",
                Source_Port="59000",
                Dest_Port="59000"
            }

};

        public class Dnat
        {
            public string Name { get; set; } = "test";
            public string Interface { get; set; } = "wwan0";
            public string Proto { get; set; } = "udp";
            public string Source_IP { get; set; } = "192.168.6.200";
            public string GateWay { get; set; } = "192.168.6.1";
            public string Source_Port { get; set; } = "5000";
            public string Dest_IP { get; set; } = "192.168.200.5";
            public string Dest_Port { get; set; } = "5000";
            public string Start { get; set; } = "01:00";
            public string Ends { get; set; } = "07:00";

        }
    }

    /// <summary>
    /// 配置访问控制列表
    /// </summary>
    public class SetACL : Status
    {
        public ACL[] AclRule { get; set; } = new ACL[] { new ACL(),
        new ACL()
        {
            Name="time",
            In_Interface="wwan0",
            Proto="ip",
            Source_Port="5600",
            Dest_Port="5600"
        }
        };
        public class ACL
        {
            public string Name { get; set; } = "test";
            public string Target { get; set; } = "ACCEPT";
            public string In_Interface { get; set; } = "vlan1";
            public string Out_Interface { get; set; } = "vlan1";
            public string Proto { get; set; } = "udp";
            public string Source_IP { get; set; } = "192.168.6.100";
            public string Source_Port { get; set; } = "5000";
            public string Dest_IP { get; set; } = "192.168.200.5";
            public string Dest_Port { get; set; } = "5000";
            public string Start { get; set; } = "01:00";
            public string Ends { get; set; } = "07:00";

        }
    }

    /// <summary>
    /// 下载业务程序
    /// </summary>
    public class DownApp : Status
    {
        public string Url { get; set; }
        public string Username { get; set; } = "";
        public string Password { get; set; } = "";
        public string Sha256sum { get; set; }
        public int Tries { get; set; } = 5;
        //public string Type { get; set; }
        public string IsRun { get; set; } = "false";
    }

    /// <summary>
    /// 配置WIFI-AP模式
    /// </summary>
    public class WIFI_AP : Status
    {
        public string Enabled { get; set; } = "true";
        public string Mode { get; set; } = "ap";
        public string Band { get; set; } = "2.4";
        public string SSID { get; set; } = "Huawow2.4G5";
        public string Wifi6 { get; set; } = "true";
        public string Channel { get; set; } = "0";
        public string Bridge { get; set; } = "lan";
        public string IPaddr { get; set; } = "";
        public string Hidden { get; set; } = "false";
        public int Max_num_sta { get; set; } = 24;
        public string VerificationMethod { get; set; } = "psk2";
        public string PassWord { get; set; } = "1234567890";
        public string FastRoaming { get; set; } = "false";
        public string MobilityDomain { get; set; } = "ffff";
        public int Reassociation_Deadline { get; set; } = 20000;
        public string MACFilter { get; set; } = "disable";
        public string[] MACList { get; set; } = new string[] { };
    }

    /// <summary>
    /// 配置WIFI-STA模式
    /// </summary>
    public class WIFI_STA : Status
    {
        public string Enabled { get; set; } = "true";
        public string Mode { get; set; } = "sta";
        public string Band { get; set; } = "2.4";
        public string AP_SSID { get; set; } = "华沃通信";
        public string Sta_Password { get; set; } = "qwert123";
        public string Sta_Proto { get; set; } = "dhcp";
        public string Sta_IPaddr { get; set; } = "";
        public string Gateway { get; set; } = "";
    }

    /// <summary>
    /// 配置WIFI-MESH模式
    /// </summary>
    public class WIFI_MESH : Status
    {
        public string Enabled { get; set; } = "true";
        public string Mode { get; set; } = "mesh";
        public string Band { get; set; } = "2.4";
        public string SSID { get; set; } = "HUAWOW_MESH";
        public string Sta_Password { get; set; } = "12345678";
        public string Mesh_Bridge { get; set; } = "vlan1";
        public string Mesh_Frequency { get; set; } = "  2.447 GHz (Channel 8)";
        public string Mesh_Proto { get; set; } = "";
        public string Mesh_IPaddr { get; set; } = "";
    }

    /// <summary>
    /// 传感器离线数据召测
    /// </summary>
    public class SensorCall:Status
    {
        /// <summary>
        /// 开始时间
        /// </summary>
        public string Start { get; set; } = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
        /// <summary>
        /// 结束时间
        /// </summary>
        public string End { get; set; }= DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        /// <summary>
        /// 是否删除本次召测数据
        /// </summary>
        public string IsDel { get; set; } = "false";
    }

}
